define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        _queryString: '',
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'company/testimonial/index' + Controller._queryString,
                    add_url: 'company/testimonial/add' + Controller._queryString,
                    edit_url: 'company/testimonial/edit',
                    del_url: 'company/testimonial/del',
                    multi_url: 'company/testimonial/multi',
                    import_url: 'company/testimonial/import',
                    table: 'company_testimonial',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'company_name', title: __('Company_name'), operate: 'LIKE', },
                        {field: 'position', title: __('Position'), operate: 'LIKE'},
                        {field: 'avatarimage', title: __('Avatarimage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'comment', title: __('Comment'), operate: 'LIKE', cellStyle: function () {
                                return {
                                    css: {
                                        "max-width": "250px",
                                        "text-overflow": "ellipsis",
                                        "white-space": "initial"
                                    }
                                };
                            }},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            queryString: function () {
                return location.search.replace("dialog=1", "").split('&').filter(function (item) {
                    return !!item;
                }).join("&");
            }
        }
    };
    Controller._queryString = Controller.api.queryString();
    return Controller;
});